<?php /* Smarty version 2.6.20, created on 2016-04-11 19:47:34
         compiled from list.htm */ ?>
<link href="admin.css" rel="stylesheet" type="text/css" />
<script src="<?php echo $this->_tpl_vars['config']['weburl']; ?>
/script/jquery-1.4.4.min.js" type="text/javascript" charset="utf-8" ></script>

<?php if ($_GET['operation'] == 'property'): ?>
    <div class="container">
    	<div class="oflow"  style="height:517px">
        <table class="table4 mt20">
            <thead>
            <tr>
                <td class="pl20">扩展属性值</td>
                <td width="70" class="ac">操作</td>
            </tr>
            </thead>
            <tbody>
            <?php $_from = $this->_tpl_vars['re']; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array'); }if (count($_from)):
    foreach ($_from as $this->_tpl_vars['num'] => $this->_tpl_vars['list']):
?>
        <tr>
            <td class="pl20">
            <input type="text" class="w350"  name="item_name[]" value="<?php echo $this->_tpl_vars['list']; ?>
" />
            </td>
            
			<td class="ac"><div><a href="javascript:;" class="deleterow" onclick="deleterow(this)">删除</a></div></td>
        </tr>
        <?php endforeach; endif; unset($_from); ?>
            
            
            <tr>
                <td colspan="99">
                <ul class="button">
                    <li class="button">
                        <a class="a_button" onClick="addrow(this,0)" href="javascript:void(0);">添加扩展属性值</a>
                    </li>
                </ul>
                </td>
            </tr>
            </tbody>
        </table>
        </div>
        <div class="dialog_button">
        <input id="save" type="button" value="保存">
        <input name="act" type="hidden" id="action" value="<?php if (! $_GET['editid']): ?>save<?php else: ?>edit<?php endif; ?>">   
        </div>
        <div id="error"></div> 
    </div>
    <script>
	$('#save').click(function(){
		var str = '';
		var id = "<?php echo $_GET['id']; ?>
";
		$.each($(".container input[name='item_name[]']"),function(i){
			
			var aa= $(this).val();
			if(aa)
			{
				if(!str)
					str = aa;
				else
					str = str+','+aa;
			}
		});
        var iframe=window.parent.document.getElementById("iframe_property").contentWindow;

		var ss=iframe.$("#property").find("input[nc_type='"+id+"']");
		$.each(ss,function(i){
			
			$(this).val(str);
		});
        window.parent.DialogManager.close("list");
    });

	var rowtypedata = [
        [
			['<input type="text" class="w350" name="item_name[]" value="" />','pl20'], 
            ['<div><a href="javascript:;" class="deleterow" onClick="deleterow(this)">删除</a></div>','ac'],
        ],
    ];

	var addrowdirect = 0;
    var j = 1;
	
    function addrow(obj, type) {
        var table = obj.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode;
        if(!addrowdirect) {
            var row = table.insertRow(obj.parentNode.parentNode.parentNode.parentNode.rowIndex);
        } else {
            var row = table.insertRow(obj.parentNode.parentNode.parentNode.parentNode.rowIndex + addrowdirect);
        }
        
        var typedata = rowtypedata[type];
        
        for(var i = 0; i <= typedata.length - 1; i++) {
            
            var cell = row.insertCell(i);
			if(typedata[i][1]) {
				cell.className = typedata[i][1];
			}
            var tmp = typedata[i][0];
            cell.innerHTML = tmp;
        
        }
        addrowdirect = 0;
        j++;
    }
    function deleterow(obj) {
        var table = obj.parentNode.parentNode.parentNode.parentNode.parentNode;
        var tr = obj.parentNode.parentNode.parentNode;
        table.deleteRow(tr.rowIndex);
    }
    </script>
<?php elseif ($_GET['operation'] == 'tplproperty'): ?>
    <?php if ($this->_tpl_vars['de']): ?>
    <script src="<?php echo $this->_tpl_vars['config']['weburl']; ?>
/script/base.js" type="text/javascript" charset="utf-8" ></script>
    <form action="" method="post">
    <div class="container list">
        <div class="left">
            <div class="mt"><h2>请选择属性</h2></div>
            <div class="mc">
            <ul id="ul">
                <?php $_from = $this->_tpl_vars['de']; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array'); }if (count($_from)):
    foreach ($_from as $this->_tpl_vars['num'] => $this->_tpl_vars['list']):
?>
                    <li>
                        <input type="radio" id="id<?php echo $this->_tpl_vars['num']; ?>
" value="<?php echo $this->_tpl_vars['list']['id']; ?>
" name="id">
                        <label for="id<?php echo $this->_tpl_vars['num']; ?>
"><?php echo $this->_tpl_vars['list']['field_name']; ?>
</label>
                    </li>
                <?php endforeach; endif; unset($_from); ?>
            </ul>
            </div>
        </div>
        <div class="right">
            <div class="mt"><h2>选择属性值</h2></div>
            <div class="mc">
                <div class="tips">请在左侧列表选择属性！</div>
                <?php $_from = $this->_tpl_vars['de']; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array'); }if (count($_from)):
    foreach ($_from as $this->_tpl_vars['num'] => $this->_tpl_vars['list']):
?>
                <dl class="hidden">
                    <dt>
                    <h2><?php echo $this->_tpl_vars['list']['field_name']; ?>
</h2>
                    <p><?php echo $this->_tpl_vars['list']['field_desc']; ?>
</p>
                    </dt>
                    <?php $_from = $this->_tpl_vars['list']['items']; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array'); }if (count($_from)):
    foreach ($_from as $this->_tpl_vars['skey'] => $this->_tpl_vars['slist']):
?>
                         <dd property_id="<?php echo $this->_tpl_vars['skey']; ?>
" property_cat="<?php echo $this->_tpl_vars['list']['id']; ?>
"><?php echo $this->_tpl_vars['slist']; ?>
</dd>
                    <?php endforeach; endif; unset($_from); ?>
                </dl>
                <?php endforeach; endif; unset($_from); ?>
            </div>
        </div>
        <div class="dialog_button">
        <input id="save" type="button" value="保存">
        <input name="act" type="hidden" id="action" value="<?php if (! $_GET['editid']): ?>save<?php else: ?>edit<?php endif; ?>">   
        </div>
        <div id="error"></div> 
    </div>
    </form>  
    <?php else: ?>
        <div class="norecord"><i></i><span>暂无符合条件的数据记录</span></div>
    <?php endif; ?>
    <script>
    
    var property_arr=[];
    
    $.each($('.left li'),function(i){
        $(this).find("input[type='radio']").live('click',function(){
    
            $($('.right dl')[i]).removeClass("hidden").siblings().addClass("hidden");
        });	
        
        
        <?php if ($_GET['tpl']): ?>
        	if($(this).find("input[type='radio']").val()==<?php echo $_GET['tpl']; ?>
){
        		$(this).find("input[type='radio']").attr('checked','checked');
        		$($('.right dl')[i]).removeClass("hidden").siblings().addClass("hidden");
        	}
	

				<?php endif; ?>
        
				
    });
    
    
    var id='<?php echo $_GET['id']; ?>
';
			if(id.indexOf('n')!=0){
				$("input[type='radio']:not(:checked)").attr('disabled','1');
			}
    
    
    <?php if ($_GET['v'] && $_GET['tpl']): ?>
    	property_arr[<?php echo $_GET['tpl']; ?>
]=[<?php echo $_GET['v']; ?>
]
    	
    		$.each(property_arr[<?php echo $_GET['tpl']; ?>
],function(k,v){
    			if(v>0){
    				$('[property_id='+v+'][property_cat=<?php echo $_GET['tpl']; ?>
]').addClass('cur');
    			}
    			
    		})
    	


		<?php endif; ?>
    

    
    $('[property_id]').click(function(){
    	var c =parseInt($(this).attr('property_cat'));
    	var v =parseInt($(this).attr('property_id'));
    	if(!property_arr[c]){
    		property_arr[c]=[];
    	}
    	
    	
    	if($.inArray(v,property_arr[c])>-1||$.inArray(-v,property_arr[c])>-1){
    		
    		if(id.indexOf('n')==0){
    			property_arr[c]=$.grep(property_arr[c], function(n){
    				return n==v;
    			}, true);
				}else{
					property_arr[c][$.inArray($.inArray(v,property_arr[c])>-1?v:-v,property_arr[c])]=$.inArray(v,property_arr[c])>-1?-v:v;

				}
    		
    		$.inArray(v,property_arr[c])>-1?$(this).addClass('cur'):$(this).removeClass('cur');
    	}else{
    		property_arr[c].push(v);
    		$(this).addClass('cur');
    	}
    	
    	
    	
    })
    
    $('#save').click(function(){
    	
    	
    	var obj=$("input[type='radio']:checked");
        if(!obj.length)
        {
        	parent.message_warning('msg_error','警告','对不起，请选择数据，再进行操作!');

            
            return false;
        }
        
        else{
        	
          var id = "<?php echo $_GET['id']; ?>
";
          var iframe=window.parent.document.getElementById("iframe_property").contentWindow;
            
          var ss=iframe.$("#property").find("input[nc_type='"+id+"']");
          var vss=iframe.$("#property").find("input[nc_type='v_"+id+"']");
          var tss=iframe.$("#property").find("input[nc_type='tpl_"+id+"']");

        	
          var sval=property_arr[obj.val()];
          
          var stxt =[];
          $.each(sval,function(k,v){
  					if(v>0){
  						stxt.push( $('[property_id='+v+'][property_cat='+obj.val()+']').text());
  						
  					}
  				})
          ss.val(stxt);
          vss.val(sval);
          tss.val(obj.val());
  				
        	 window.parent.DialogManager.close("list");
        	//alert(stxt);
        	return false;
        }
       
    });
    </script>
<?php else: ?>
    <?php if ($this->_tpl_vars['de']): ?>
    <script src="<?php echo $this->_tpl_vars['config']['weburl']; ?>
/script/base.js" type="text/javascript" charset="utf-8" ></script>
    <form action="" method="post">
    <div class="container list">
        <div class="left">
            <div class="mt"><h2>请选择属性</h2></div>
            <div class="mc">
            <ul id="ul">
                <?php $_from = $this->_tpl_vars['de']; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array'); }if (count($_from)):
    foreach ($_from as $this->_tpl_vars['num'] => $this->_tpl_vars['list']):
?>
                    <li>
                        <input type="checkbox" id="id<?php echo $this->_tpl_vars['num']; ?>
" value="<?php echo $this->_tpl_vars['list']['id']; ?>
" name="id" <?php if ($this->_tpl_vars['list']['field'] == 'color'): ?> is_color="1" <?php endif; ?>>
                        <label for="id<?php echo $this->_tpl_vars['num']; ?>
"><?php echo $this->_tpl_vars['list']['field_name']; ?>
</label>
                    </li>
                <?php endforeach; endif; unset($_from); ?>
            </ul>
            </div>
        </div>
        <div class="right">
            <div class="mt"><h2>属性预览区</h2></div>
            <div class="mc">
                <div class="tips">请在左侧列表选择属性！</div>
                <?php $_from = $this->_tpl_vars['de']; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array'); }if (count($_from)):
    foreach ($_from as $this->_tpl_vars['num'] => $this->_tpl_vars['list']):
?>
                <dl class="hidden">
                    <dt>
                    <h2><?php echo $this->_tpl_vars['list']['field_name']; ?>
</h2>
                    <p><?php echo $this->_tpl_vars['list']['field_desc']; ?>
</p>
                    </dt>
                    <?php $_from = $this->_tpl_vars['list']['items']; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array'); }if (count($_from)):
    foreach ($_from as $this->_tpl_vars['skey'] => $this->_tpl_vars['slist']):
?>
                         <dd property_id="<?php echo $this->_tpl_vars['skey']; ?>
" property_cat="<?php echo $this->_tpl_vars['list']['id']; ?>
" ><?php echo $this->_tpl_vars['slist']; ?>
</dd>
                    <?php endforeach; endif; unset($_from); ?>
                </dl>
                <?php endforeach; endif; unset($_from); ?>
            </div>
        </div>
        <div class="dialog_button">
        <input id="save" type="button" value="保存">
        <input name="act" type="hidden" id="action" value="<?php if (! $_GET['editid']): ?>save<?php else: ?>edit<?php endif; ?>">   
        </div>
        <div id="error"></div> 
    </div>
    </form>  
    <?php else: ?>
        <div class="norecord"><i></i><span>暂无符合条件的数据记录</span></div>
    <?php endif; ?>
    <script>
    var  tpl_arr=[];
    var property_arr=[];
    
    <?php if ($_GET['v']): ?>
    
	var vals='<?php echo $_GET['v']; ?>
';
	
	var vals_arr=vals.split('|');
	
	$.each(vals_arr,function(k,v){
		var t_arr=v.split(':');
		tpl_arr.push(t_arr[0])
		property_arr[t_arr[0]]=$.map(t_arr[1].split(','),function(n){return parseInt(n)});
		
		
	})
<?php endif; ?>


    


    
    $.each($('.left li'),function(i){
        $(this).find("input[type='checkbox']").live('click',function(){
    
        	if($(this).is(":checked")){
        		
        		if($("input[type='checkbox']:checked[is_color=1]").size()>1){
                	parent.message_warning('msg_error','警告','对不起，只能有一个属性上传图片!');
                	$(this).removeAttr('checked');
                	return;
        		}
        		
        	
            $($('.right dl')[i]).removeClass("hidden");
        	}else{
                $($('.right dl')[i]).addClass("hidden");

        	}
        	if($("input[type='checkbox']:checked").size()>0){
        		$('.tips').hide();
        	}else{
        		$('.tips').show();
        	}
        	
        	
        });	
        
        
		if($.inArray($(this).find("input[type='checkbox']").val(),tpl_arr)>-1){
			$(this).find("input[type='checkbox']").attr('checked','checked');
			 $($('.right dl')[i]).removeClass("hidden");
		}

        
    });
    

    if($("input[type='checkbox']:checked").size()>0){
		$('.tips').hide();
		}else{
		$('.tips').show();
		}
    
    $.each(tpl_arr,function(key,item){
    	$.each(property_arr[item],function(k,v){
				$('[property_id='+v+'][property_cat='+item+']').addClass('cur');
    	})
		
	})
    	
	
	

	
	    $('[property_id]').click(function(){
	    	
	   	var is_edit ='<?php echo $_GET['is_edit']; ?>
'
	    var c =parseInt($(this).attr('property_cat'));
    	var v =parseInt($(this).attr('property_id'));
    	if(!property_arr[c]){
    		property_arr[c]=[];
    	}
    	if($.inArray(v,property_arr[c])>-1||$.inArray(-v,property_arr[c])>-1){
    		
    		if(is_edit==0){
    			property_arr[c]=$.grep(property_arr[c], function(n){
    				return n==v;
    			}, true);
				}else{
					property_arr[c][$.inArray($.inArray(v,property_arr[c])>-1?v:-v,property_arr[c])]=$.inArray(v,property_arr[c])>-1?-v:v;
				}
    		
    		$.inArray(v,property_arr[c])>-1?$(this).addClass('cur'):$(this).removeClass('cur');
    	}else{
    		property_arr[c].push(v);
    		$(this).addClass('cur');
    	}
    	
    	
    	
    })
	


		
    
    
    $('#save').click(function(){
        var obj=$("input[type='checkbox']:checked");
        if(!obj.length)
        {
        	parent.message_warning('msg_error','警告','对不起，请选择数据，再进行操作!');

            
            return false;
        }
        var iframe=window.parent.document.getElementById("iframe_property").contentWindow;
        
        
        
        iframe.spec_data=property_arr;
        var stxt =[];
        $.each(property_arr,function(k,v){
        	if(!v)return true;
        	stxt[k]=[];
        	$.each(v,function(i,n){
        		if(n>0){
							stxt[k][n]=$('[property_id='+n+'][property_cat='+k+']').text();
						}
        		
        	})
					
				})
         iframe.spec_txt_data=stxt;
        iframe.addrow("list",'<?php echo $_GET['type']; ?>
',2);
        window.parent.DialogManager.close("list");
    });
    </script>
<?php endif; ?>